#ifndef __MYRPCCHANNEL_H__
#define __MYRPCCHANNEL_H__

#include <google/protobuf/service.h>
#include "zookeeperutil.h"

class MyRPCChannel : public google::protobuf::RpcChannel
{
public:
    MyRPCChannel(bool connectNow);
    virtual ~MyRPCChannel(){}
    void CallMethod(const ::google::protobuf::MethodDescriptor* method,
                          ::google::protobuf::RpcController* controller, 
                          const ::google::protobuf::Message* request,
                          ::google::protobuf::Message* response, 
                          ::google::protobuf::Closure* done) override;
private:
    int m_clientfd; // 与客户端通信的文件描述符
    std::string service_name;
    std::string m_ip;
    uint16_t m_port;
    std::string method_name;
    int m_idx; // 字符串中划分ip和port的下标值
    bool newConnect(const char* ip, uint16_t port);
    std::string QueryServiceHost(ZKClient* zkclient, std::string service_name, std::string method_name, int& idx);
};

#endif